home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 62
/
Volume 62 - JOGO DISK .iso
/
Games
/
missioncandy.swf
/
scripts
/
frame_1
/
DoAction.as
Wrap
Text File
|
2008-03-17
|
16KB
|
576 lines
function goGame()
{
stopAllSounds();
gotoAndStop("GAME1");
play();
}
function goIntro()
{
stopAllSounds();
gotoAndStop("INTRO");
play();
}
function goEnding()
{
stopAllSounds();
gotoAndStop("ENDING");
play();
}
function goHowto()
{
gotoAndStop("HOWTO");
play();
}
function initGmae()
{
game_start = true;
gof = 4 - m_life;
life_mc.gotoAndStop(gof);
sBuf = 0;
charSpeed = 5;
lastLR = 3;
char_mc.goX = char_mc._x;
ground2_mc.goX = ground2_mc._x;
keyAction = 0;
jumpFr = 0;
char_mc.incomming = false;
char_mc.incommingLmt = 90;
char_mc.incommingCnt = 0;
char_mc.lampLmt = 2;
char_mc.lmapCnt = 0;
this.onEnterFrame = function()
{
if(game_start == true)
{
updateScore();
if(char_mc.incomming == true)
{
char_mc.incommingCnt = char_mc.incommingCnt + 1;
if(char_mc.incommingCnt < char_mc.incommingLmt)
{
if(char_mc.lampCnt == 0)
{
if(char_mc._alpha == 100)
{
char_mc._alpha = 50;
}
else
{
char_mc._alpha = 100;
}
}
if(char_mc.lampCnt < char_mc.lampLmt)
{
char_mc.lampCnt = char_mc.lampCnt + 1;
}
else
{
char_mc.lampCnt = 0;
}
}
else
{
char_mc.incommingCnt = 0;
char_mc.incomming = false;
char_mc._alpha = 100;
}
}
if(Key.isDown(37))
{
if(keyAction == 0 or keyAction == 1 or keyAction == 2)
{
keyAction = 1;
}
}
if(Key.isDown(39))
{
if(keyAction == 0 or keyAction == 1 or keyAction == 2)
{
keyAction = 2;
}
}
if(Key.isDown(38))
{
if(keyAction == 0 or keyAction == 1 or keyAction == 2)
{
jumpSnd_mc.gotoAndPlay(2);
jumpFr = 0;
jumpYspeed = -13;
if(keyAction == 0)
{
jumpAction(0);
}
if(keyAction == 1)
{
jumpAction(- charSpeed);
}
if(keyAction == 2)
{
jumpAction(charSpeed);
}
}
}
if(Key.isDown(32))
{
if(keyAction == 0 or keyAction == 1 or keyAction == 2)
{
keyAction = 4;
}
}
if(keyAction == 1)
{
if(char_mc.goX >= char_mc._x)
{
if(char_mc._currentframe != 4)
{
char_mc.gotoAndStop(4);
}
if(char_mc._x - charSpeed < stageWidth / 2 and ground2_mc._x + charSpeed < 0)
{
ground2_mc.goX = ground2_mc._x + charSpeed;
balanceGround();
}
else
{
char_mc.goX = char_mc._x - charSpeed;
}
lastLR = 4;
if(ground_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false and ground2_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false)
{
jumpFr = 0;
jumpYspeed = 10;
jumpAction(0);
}
else
{
keyAction = 0;
}
}
}
else if(keyAction == 2)
{
if(char_mc.goX <= char_mc._x)
{
if(char_mc._currentframe != 3)
{
char_mc.gotoAndStop(3);
}
if(char_mc._x + charSpeed >= stageWidth / 2 and ground2_mc._x - charSpeed > stageWidth - ground2_mc._width)
{
ground2_mc.goX = ground2_mc._x - charSpeed;
balanceGround();
}
else
{
char_mc.goX = char_mc._x + charSpeed;
}
lastLR = 3;
if(ground_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false and ground2_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false)
{
jumpFr = 0;
jumpYspeed = 10;
jumpAction(0);
}
else
{
keyAction = 0;
}
}
}
else if(keyAction == 3)
{
if(char_mc._x + jumpXspeed >= stageWidth / 2 and jumpXspeed > 0 and ground2_mc._x - charSpeed > stageWidth - ground2_mc._width)
{
ground2_mc.goX -= charSpeed;
}
else if(char_mc._x + jumpXspeed <= stageWidth / 2 and jumpXspeed < 0 and ground2_mc._x + charSpeed < 0)
{
ground2_mc.goX += charSpeed;
}
else if(char_mc._x + charSpeed > stageWidth and ground2_mc._x - charSpeed <= stageWidth - ground2_mc._width)
{
char_mc._x = stageWidth;
}
else if(char_mc._x - charSpeed < 0)
{
char_mc._x = 0;
}
else
{
char_mc._x += jumpXspeed;
}
char_mc.goX = char_mc._x;
if(jumpYspeed > 10)
{
jumpYspeed = 10;
}
char_mc._y += jumpYspeed;
jumpYspeed += 1;
if(jumpYspeed > 0)
{
if(ground_mc.hitTest(char_mc._x,char_mc._y + jumpYspeed,true))
{
tempY = Math.round(char_mc._y + jumpYspeed);
nQuit = true;
while(nQuit)
{
tempY--;
if(ground_mc.hitTest(char_mc._x,tempY,true) == false)
{
tempY++;
nQuit = false;
}
}
char_mc._y = tempY;
keyAction = 0;
}
else if(ground2_mc.hitTest(char_mc._x,char_mc._y + jumpYspeed,true))
{
tempY = Math.round(char_mc._y + jumpYspeed);
nQuit = true;
while(nQuit)
{
tempY--;
if(ground2_mc.hitTest(char_mc._x,tempY,true) == false)
{
tempY++;
nQuit = false;
}
}
char_mc._y = tempY;
keyAction = 0;
}
else
{
char_mc._y += jumpYspeed;
}
}
jumpFr += 1;
}
else if(keyAction == 4)
{
standChar();
}
else
{
if(lastLR == 3 and keyAction != 5)
{
char_mc.gotoAndStop(1);
}
if(lastLR == 4 and keyAction != 5)
{
char_mc.gotoAndStop(2);
}
}
if(ground2_mc.goX < ground2_mc._x)
{
ground2_mc._x -= charSpeed;
balanceGround();
allMonsterMove(- charSpeed);
allEatMove(- charSpeed);
}
if(ground2_mc.goX > ground2_mc._x)
{
ground2_mc._x += charSpeed;
balanceGround();
allMonsterMove(charSpeed);
allEatMove(charSpeed);
}
if(char_mc.goX > char_mc._x)
{
if(char_mc._x + charSpeed > stageWidth and ground2_mc._x - charSpeed <= stageWidth - ground2_mc._width)
{
char_mc._x = stageWidth;
char_mc.goX = stageWidth;
}
else
{
char_mc._x += charSpeed;
}
}
if(char_mc.goX < char_mc._x)
{
if(char_mc._x - charSpeed < 0)
{
char_mc._x = 0;
char_mc.goX = 0;
}
else
{
char_mc._x -= charSpeed;
}
}
if(Math.abs(char_mc.goX - char_mc._x) < charSpeed)
{
char_mc.goX = Math.round(char_mc.goX);
char_mc._x = Math.round(char_mc.goX);
}
if(end_mc.hitTest(char_mc._x,char_mc._y - char_mc._height,true))
{
if(Number(eat_txt.text) == 0)
{
game_start = false;
pause_mc.gotoAndStop(1);
pauseBtn_mc.gotoAndStop(1);
clear_mc.gotoAndPlay(2);
}
else if(eatDsp_mc._currentframe == 1)
{
eatDsp_mc.gotoAndPlay(2);
}
}
}
};
}
function eatAI(ms_mc)
{
eat_array[eat_array.length] = ms_mc;
ms_mc.onEnterFrame = function()
{
if(this.hitTest(char_mc._x,this._y,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe == 1)
{
this.gotoAndPlay(2);
i = 0;
while(i < eat_array.length)
{
if(eat_array[i] == this)
{
eat_array.splice(i,1);
i = eat_array.length + 2;
update_eat();
}
i++;
}
}
};
update_eat();
}
function update_eat()
{
if(eat_array.length < 10)
{
eat_txt.text = "0" + eat_array.length;
}
else
{
eat_txt.text = eat_array.length;
}
}
function allEatMove(mSpeed)
{
i = 0;
while(i < eat_array.length)
{
eat_array[i]._x += mSpeed;
i++;
}
}
function monsterAI1(ms_mc, getSpeed)
{
monster_array[monster_array.length] = ms_mc;
ms_mc.mSpeed = getSpeed;
gof = Math.floor(Math.random() * 2) + 1;
ms_mc.eng = 2;
ms_mc.gotoAndStop(gof);
ms_mc.onEnterFrame = function()
{
if(game_start == true)
{
if(this._currentframe == 1)
{
if(ground2_mc.hitTest(this._x - 10,this._y + 5,true))
{
this._x -= this.mSpeed;
}
else
{
this.gotoAndStop(2);
}
}
if(this._currentframe == 2)
{
if(ground2_mc.hitTest(this._x + 10,this._y + 5,true))
{
this._x += this.mSpeed;
}
else
{
this.gotoAndStop(1);
}
}
if(char_mc.char_mc.fog_mc.hitTest(this._x,char_mc._y - char_mc._height / 2,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe != 5 and this._currentframe != 6)
{
if(char_mc._x < this._x)
{
this.gotoAndStop(3);
}
else
{
this.gotoAndStop(4);
}
}
else if(this.hit_mc.hitTest(char_mc) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and char_mc.incomming == false and (keyAction == 1 or keyAction == 2 or keyAction == 0))
{
char_mc.incomming = true;
if(lastLR == 3)
{
char_mc.gotoAndStop(9);
}
if(lastLR == 4)
{
char_mc.gotoAndStop(10);
}
keyAction = 5;
}
}
};
}
function monsterAI2(ms_mc, getSpeed)
{
monster_array[monster_array.length] = ms_mc;
ms_mc.mSpeed = getSpeed;
ms_mc.gotoAndStop(2);
ms_mc.eng = 2;
ms_mc.onEnterFrame = function()
{
if(game_start == true)
{
if(Math.abs(this._x - char_mc._x) <= stageWidth and Math.abs(this._x - char_mc._x) > Math.abs(this.mSpeed) and (this._currentframe == 1 or this._currentframe == 2))
{
if(Math.abs(this._x - char_mc._x) <= this.mSpeed)
{
this._x = char_mc._x;
}
else if(this._x > char_mc._x)
{
this.mSpeed = Math.abs(this.mSpeed) * -1;
if(this._currentframe != 1)
{
this.gotoAndStop(1);
}
}
else
{
this.mSpeed = Math.abs(this.mSpeed);
if(this._currentframe != 2)
{
this.gotoAndStop(2);
}
}
this._x += this.mSpeed;
}
if(char_mc.char_mc.fog_mc.hitTest(this._x,char_mc._y - char_mc._height / 2,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe != 5 and this._currentframe != 6)
{
if(char_mc._x < this._x)
{
this.gotoAndStop(3);
}
else
{
this.gotoAndStop(4);
}
}
else if(this.hit_mc.hitTest(char_mc) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and char_mc.incomming == false and (keyAction == 1 or keyAction == 2 or keyAction == 0))
{
char_mc.incomming = true;
if(lastLR == 3)
{
char_mc.gotoAndStop(9);
}
if(lastLR == 4)
{
char_mc.gotoAndStop(10);
}
keyAction = 5;
}
}
};
}
function allMonsterMove(mSpeed)
{
i = 0;
while(i < monster_array.length)
{
monster_array[i]._x += mSpeed;
i++;
}
}
function standChar()
{
if(lastLR == 3 and char_mc._currentframe != 5)
{
char_mc.gotoAndStop(5);
}
if(lastLR == 4 and char_mc._currentframe != 6)
{
char_mc.gotoAndStop(6);
}
}
function jumpAction(xpd)
{
if(keyAction == 0)
{
jumpXspeed = 0;
}
else if(keyAction == 1)
{
jumpXspeed = xpd;
char_mc.gotoAndStop(8);
}
else if(keyAction == 2)
{
jumpXspeed = xpd;
char_mc.gotoAndStop(7);
}
keyAction = 3;
}
function balanceGround()
{
ground3_mc._x = ground2_mc._x;
ground_mc._x = ground2_mc._x;
a = (bg_mc._width - stageWidth) / (ground2_mc._width - stageWidth);
b = 1 - a * 0.5;
bg_mc._x = a * ground2_mc._x + b;
}
function updateScore()
{
if(now_score < m_score)
{
scoreSnd_mc.gotoAndPlay(2);
now_score += 5;
}
if(now_score > m_score)
{
now_score = m_score;
}
m_score_str = String(now_score);
if(m_score_str.length == 3)
{
m_score_str = "0" + m_score_str;
}
if(m_score_str.length == 2)
{
m_score_str = "00" + m_score_str;
}
if(m_score_str.length == 1)
{
m_score_str = "000" + m_score_str;
}
var _loc2_ = 1;
while(_loc2_ < m_score_str.length + 1)
{
this.score_mc["num" + _loc2_].gotoAndStop(int(m_score_str.substr(_loc2_ - 1,1)) + 1);
_loc2_ = _loc2_ + 1;
}
}
stageWidth = 500;
delete monster_array;
delete eat_array;
m_level = 1;
monster_array = new Array();
eat_array = new Array();
m_score = 0;
now_score = 0;
m_life = 3;
game_start = false;